package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import org.json.JSONArray;

import com.mongodb.BasicDBList;
import com.ymt.core.tool.FormatUtil;
import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :ProductBasicInfo.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
/**
 * @author cszhangyi
 *
 */
public class LiveBasicInfoWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriver("LiveBasicInfo");

	public LiveBasicInfoWapper(){
	}
		
	public LiveBasicInfoBean getByActivityId(int activityId) throws Exception {
	    ArrayList<String> list = mdd.selectPart("{\"ActivityId\":" + activityId +"}");
	    
	    return list.size()>0?(LiveBasicInfoBean) FormatUtil.GSONToObject(list.get(0),LiveBasicInfoBean.class):null;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map<String, Object> getLastLiveInfo() throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("", "", 1, "{'ActivityId':-1}");;
		
		return list.size()>0 ? list.get(0): null;
	}
	    

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map<String,Object> getActivityId(int activityId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ActivityId\":" + activityId + "}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	    
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	
	public int getCountByProductId(int activityId) throws Exception{
		return mdd.selectPartLimitToMap("{\"ActivityId\":" + activityId + "}",50).size();
	}
	
	
	public static void main(String[] args) throws Exception {
		
//		boolean a= new LiveBasicInfoWapper().update(MapUtil.hashMap("ActivityId", 144280),MapUtil.hashMap("StartTime",new Date()));
		System.out.println(((BasicDBList) new LiveBasicInfoWapper().getLastLiveInfo().get("Brands")).get(0));
//		System.out.println(a);
		
		//Mongo
		
	}    
	
	    
}
